/*
 * @Descripttion:
 * @Author: sunchen
 * @Date: 2023-05-05 14:52:20
 * @LastEditors: wangru
 * @LastEditTime: 2023-11-02 14:55:15
 */
import { createApp } from "vue";
import "./style.css";
import "./assets/css/common.scss";
import "./permission";
import router from "./router";
import antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
import MainApp from "./App.vue";
import { createPinia } from "pinia";
import { createFromIconfontCN } from "@ant-design/icons-vue";
import piniaPersist from "pinia-plugin-persist";

import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
// import vClickOutside from 'click-outside-vue3';
let app;

const IconFont = createFromIconfontCN({
	//at.alicdn.com/t/c/font_4285304_ydzy8q4zkd.js
	scriptUrl: "https://at.alicdn.com/t/c/font_4285304_vbu4cj1ag8.js",
});

// process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
// import.meta.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'

function render(props) {
	console.log("props", props);
	const { container } = props || {};
	app = createApp(MainApp);
	//获取public目录下所有的文件信息
	const modulesFiles = import.meta.globEager(
		"@/components/global/*/index.vue"
	);
	const pathList = [];
	//遍历拿到所有的文件名称
	for (const path in modulesFiles) {
		pathList.push(path);
	}
	//全局批量注册components下所有组件
	pathList.forEach((path) => {
		const componentEl = modulesFiles[path].default;
		if (app && componentEl.name) {
			app.component(componentEl.name, componentEl);
		}
	});

	const pinia = createPinia();
	pinia.use(piniaPersist);

	app.component("IconFont", IconFont);

	app.use(pinia);
	app.use(antd);
	app.use(router);

	// app.use(vClickOutside);
	app.mount(container ? container.querySelector("#app") : "#app");
}

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
	render();
}
